/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import database.ProductManagerDAO;
import database.*;
import database.SupplierDAO;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.Product;
import model.Receipt;
import model.Staff;
import model.Supplier;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/Receipt")
public class WReceipAction extends ActionSupport {
    private int currentPage;
    private int totalPage;
    private int itemsPerPage = 10; 
    private Receipt receip;
    private List<Receipt> receips;
    private Map<Integer, String> allSuppliers;
    private Map<Integer, String> allStaffs;

    public Map<Integer, String> getAllSuppliers() {
        return allSuppliers;
    }

    public void setAllSuppliers(Map<Integer, String> allSuppliers) {
        this.allSuppliers = allSuppliers;
    }

    public Map<Integer, String> getAllStaffs() {
        return allStaffs;
    }

    public void setAllStaffs(Map<Integer, String> allStaffs) {
        this.allStaffs = allStaffs;
    }
    
//    private List<Staff> staffs;
//    private List<String> suppliersName;
//    private List<String> staffsName;
//    private String yourStaffName;
//    private List<Supplier> suppliers;
//    private String yourSupplierName;
    
    private Date createDate;
    public ReceipingDAO receipDAO = new ReceipingDAO();
    public SupplierDAO supplierDAO = new SupplierDAO();
    public StaffDAO staffDAO = new StaffDAO();
    
    
    private Map<Integer, String> allProducts;
    public ProductManagerDAO productDAO = new ProductManagerDAO();
    
     public WReceipAction() {
        allProducts = new HashMap<Integer, String>();

        
        for (Product c:productDAO.GetAllProduct()) {
            allProducts.put(c.getIdProduct(), c.getName());
        }
        
        allSuppliers = new HashMap<Integer, String>();
        for(Supplier c: supplierDAO.getAllSuppliers())
        {
            allSuppliers.put(c.getIdSupplier(), c.getName());
        }
        
        allStaffs = new HashMap<Integer, String>();
        for(Staff c: staffDAO.getAllStaff())
        {
            allStaffs.put(c.getIdStaff(), c.getFirstname()+" "+c.getLastname());
        }
    }
    /**
     * @return the currentPage
     */
    public int getCurrentPage() {
        return currentPage;
    }

    /**
     * @param currentPage the currentPage to set
     */
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    /**
     * @return the totalPage
     */
    public int getTotalPage() {
        return totalPage;
    }

    /**
     * @param totalPage the totalPage to set
     */
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    /**
     * @return the itemsPerPage
     */
    public int getItemsPerPage() {
        return itemsPerPage;
    }

    /**
     * @param itemsPerPage the itemsPerPage to set
     */
    public void setItemsPerPage(int itemsPerPage) {
        this.itemsPerPage = itemsPerPage;
    }

    /**
     * @return the receip
     */
    public Receipt getReceip() {
        return receip;
    }

    /**
     * @param receip the receip to set
     */
    public void setReceip(Receipt receip) {
        this.receip = receip;
    }

    /**
     * @return the receips
     */
    public List<Receipt> getReceips() {
        return receips;
    }

    /**
     * @param receips the receips to set
     */
    public void setReceips(List<Receipt> receips) {
        this.receips = receips;
    }
    
    @Action(value= "receip-management", results = {
	@Result(name ="success",location="/manageReceipt/w_receip.jsp")
    })
    public String view()
    {    
        receips = receipDAO.getAllReceip();
        return SUCCESS; 
    }
     @Action(value="add-receipt",
             results = {
                 @Result(name="success", location="/manageReceipt/w_receipting.jsp")
             })
     public String AddReceip()
     {
//         suppliersName = new ArrayList<String>();
//         suppliers = supplierDAO.getAllSuppliers();
//         
//         staffsName = new ArrayList<String>();
//         staffs = staffDAO.getAllStaff();
//         //System.out.println(suppliers);
//         for(Supplier item: suppliers)
//         {
//             suppliersName.add(item.getName());
//         }
//         for(Staff item: staffs)
//         {
//             staffsName.add(item.getLoginName());
//         }
         return SUCCESS;
     }
     
   

    /**
     * @return the createDate
     */
    public Date getCreateDate() {
        return createDate;
    }

    /**
     * @param createDate the createDate to set
     */
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    /**
     * @return the allProducts
     */
    public Map<Integer, String> getAllProducts() {
        return allProducts;
    }

    /**
     * @param allProducts the allProducts to set
     */
    public void setAllProducts(Map<Integer, String> allProducts) {
        this.allProducts = allProducts;
    }

}
